﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GTCAS.CommonLib;

namespace GTCAS.DataAccess.Common
{
    /// <summary>
    /// Thông tin cấu hình kết nối CSDL
    /// </summary>
    public class DbConfig
    {
        /// <summary>
        /// Key giải mã Connection string
        /// </summary>
        private const string KeyCrypt = "ConnStr";
        /// <summary>
        /// Key lưu trong AppSettings
        /// </summary>
        private const string KeyDBConnectionString = "DbGTCASConnectionString";
        public DbConfig()
        {

        }
        /// <summary>
        /// Chuỗi kết nối mặc định đến DB
        /// </summary>
        public static string DefaulConnectionString
        {
            get
            {
                var key = ConfigurationManager.AppSettings[KeyDBConnectionString];
                if (!String.IsNullOrEmpty(key))
                {
                    return Crypto.DecryptString(KeyCrypt, key);
                }
                return String.Empty;
            }
        }
        /// <summary>
        /// Giải mã chuối kết nối
        /// </summary>
        /// <param name="connectionstr"></param>
        /// <returns></returns>
        public static string GetDecryptConnectionString(string connectionstr)
        {
            if (!String.IsNullOrEmpty(connectionstr))
            {
                return Crypto.DecryptString(KeyCrypt, connectionstr);
            }
            return String.Empty;
        }
        /// <summary>
        /// Schema mặc định
        /// </summary>
        public const string DefaultShemma = "GTCAS";

    }
}
